//
//  ReviewWeViewController.swift
//  globalcarbusiness
//
//  Created by dongzhenyu on 2017/8/15.
//  Copyright © 2017年 dongzhenyu. All rights reserved.
//

import UIKit

class ReviewWeViewController: UIViewController {

    var zhizhaoImage: UIImage?
    var liebiaoImage: UIImage?
    var imageArray: NSMutableArray?
    var realArray: NSMutableArray = NSMutableArray()
    var pushStr: String?
    fileprivate var xiangqingImageView: UIImageView!
    
    fileprivate lazy var tableView: UITableView = {
        let table = UITableView(frame: CGRect.zero, style: .plain)
        table.allowsSelection = false
        table.isScrollEnabled = false
        table.separatorColor = UIColor(r: 241, g: 241, b: 241)
        table.separatorInset = UIEdgeInsetsMake(0, 20, 0, 0)
        table.delegate = self
        table.dataSource = self
        return table
    }()
    
    fileprivate lazy var titleArray: NSArray = {
        let arr = ["店名", "地址", "开户银行", "银行账号", "联系电话", "服务电话", "执照编号"]
        return arr as NSArray
    }()
    
    fileprivate lazy var smallArray: NSMutableArray = NSMutableArray()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        setupNav()
        
        setupDataArray()
        
        setupUI()
    }
}

// MARK: - init code
extension ReviewWeViewController {
    fileprivate func setupNav() {
        
        if pushStr == "fromInfo" {
            title = "查看信息"
        } else {
            title = "审核中"
        }
    }
    
    fileprivate func setupDataArray() {
        
    }
    
    fileprivate func setupUI() {
        
        let scrollView = UIScrollView()
        scrollView.backgroundColor = UIColor(r: 249, g: 249, b: 249)
        scrollView.showsVerticalScrollIndicator = false
        view.addSubview(scrollView)
        scrollView.snp.makeConstraints { (make) in
            make.edges.equalToSuperview()
            make.width.equalToSuperview()
        }
        
        let stepView = UIImageView(imageName: "changtiao_03")
        scrollView.addSubview(stepView)
        stepView.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(10)
            make.width.equalTo(stepView.width * WIDTH_SCALE)
            make.centerX.equalToSuperview()
            if pushStr == "fromInfo" {
                make.height.equalTo(0)
            }
        }
        
        if pushStr == "fromInfo" {
            stepView.isHidden = true
        }
        
        scrollView.addSubview(tableView)
        tableView.snp.makeConstraints { (make) in
            make.left.right.equalToSuperview()
            make.height.equalTo(44 * titleArray.count)
            make.top.equalTo(stepView.snp.bottom)
            make.width.equalToSuperview()
        }
        
        let zhizhaoView = UIView()
        zhizhaoView.backgroundColor = UIColor.white
        scrollView.addSubview(zhizhaoView)
        zhizhaoView.snp.makeConstraints { (make) in
            make.top.equalTo(tableView.snp.bottom).offset(9*WIDTH_SCALE)
            make.left.right.equalTo(tableView)
            make.height.equalTo(196*HEIGHT_SCALE)
        }
        
        let zhizhaoLabel = UILabel()
        zhizhaoLabel.font = UIFont.systemFont(ofSize: 14*WIDTH_SCALE)
        zhizhaoLabel.textColor = UIColor(red: 0.4, green: 0.4, blue: 0.4, alpha: 1.0)
        zhizhaoLabel.text = "营业执照"
        zhizhaoView.addSubview(zhizhaoLabel)
        zhizhaoLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(21 * WIDTH_SCALE)
            make.top.equalToSuperview().offset(8*HEIGHT_SCALE)
            make.height.equalTo(20*HEIGHT_SCALE)
        }
        
        let zhizhaoImageView = UIImageView(image: zhizhaoImage)
        zhizhaoView.addSubview(zhizhaoImageView)
        zhizhaoImageView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(21*WIDTH_SCALE)
            make.top.equalTo(zhizhaoLabel.snp.bottom).offset(7*HEIGHT_SCALE)
            make.right.equalToSuperview().offset(-21*WIDTH_SCALE)
            make.height.equalTo(151*HEIGHT_SCALE)
        }
        
        let liebiaoView = UIView()
        liebiaoView.backgroundColor = UIColor.white
        scrollView.addSubview(liebiaoView)
        liebiaoView.snp.makeConstraints { (make) in
            make.top.equalTo(zhizhaoView.snp.bottom).offset(10*HEIGHT_SCALE)
            make.left.right.equalTo(zhizhaoView)
            make.height.equalTo(196*HEIGHT_SCALE)
        }
        
        let liebiaoLabel = UILabel()
        liebiaoLabel.text = "商家列表图片"
        liebiaoLabel.font = UIFont.systemFont(ofSize: 14*WIDTH_SCALE)
        liebiaoLabel.textColor = UIColor(red: 0.4, green: 0.4, blue: 0.4, alpha: 1.0)
        liebiaoView.addSubview(liebiaoLabel)
        liebiaoLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(21*WIDTH_SCALE)
            make.top.equalToSuperview().offset(8*HEIGHT_SCALE)
            make.height.equalTo(20*HEIGHT_SCALE)
        }
        
        let liebiaoImageView = UIImageView(image: liebiaoImage)
        liebiaoView.addSubview(liebiaoImageView)
        liebiaoImageView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(21*WIDTH_SCALE)
            make.top.equalTo(liebiaoLabel.snp.bottom).offset(7*HEIGHT_SCALE)
            make.right.equalToSuperview().offset(-21*WIDTH_SCALE)
            make.height.equalTo(151*HEIGHT_SCALE)
        }
        
        let xiangqingView = UIView()
        xiangqingView.backgroundColor = UIColor.white
        scrollView.addSubview(xiangqingView)
        xiangqingView.snp.makeConstraints { (make) in
            make.left.right.equalTo(liebiaoView)
            make.top.equalTo(liebiaoView.snp.bottom).offset(10*HEIGHT_SCALE)
            make.height.equalTo(345*HEIGHT_SCALE)
        }
        
        let xiangqingLabel = UILabel()
        let str1 = "商家详情图片"
        let attr1 = NSMutableAttributedString(string: str1)
        attr1.addAttributes([NSFontAttributeName: UIFont.systemFont(ofSize: 14*WIDTH_SCALE), NSForegroundColorAttributeName: UIColor(red: 0.3258, green: 0.3258, blue: 0.3258, alpha: 1.0 )], range: NSMakeRange(0, 6))
        xiangqingLabel.attributedText = attr1
        xiangqingView.addSubview(xiangqingLabel)
        xiangqingLabel.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(21*WIDTH_SCALE)
            make.top.equalToSuperview().offset(8*HEIGHT_SCALE)
            make.height.equalTo(20*HEIGHT_SCALE)
        }
        
        xiangqingImageView = UIImageView()
        if imageArray?[0] is NSDictionary {
            xiangqingImageView.image = (imageArray?[0] as! NSDictionary).allValues.first as? UIImage
        } else {
            xiangqingImageView.image = imageArray?[0] as? UIImage
        }
        xiangqingImageView.tag = 105
        xiangqingView.addSubview(xiangqingImageView)
        xiangqingImageView.snp.makeConstraints { (make) in
            make.left.equalToSuperview().offset(21*WIDTH_SCALE)
            make.right.equalToSuperview().offset(-21*WIDTH_SCALE)
            make.top.equalTo(xiangqingLabel.snp.bottom).offset(7*HEIGHT_SCALE)
            make.height.equalTo(151*HEIGHT_SCALE)
        }
        
        let submitBtn = UIButton(type: .system)
        submitBtn.backgroundColor = UIColor(red: 0.0824, green: 0.6627, blue: 1.0, alpha: 1.0)
        
        let formatter = DateFormatter()
        let date = Date()
        formatter.dateFormat = "yyyy-MM-dd"
        let str = formatter.string(from: date)
        
        submitBtn.setTitle("提交时间" + str, for: .normal)
        submitBtn.setTitleColor(UIColor.white, for: .normal)
        xiangqingView.addSubview(submitBtn)
        
        submitBtn.snp.makeConstraints { (make) in
            make.left.equalToSuperview()
            make.top.equalTo(xiangqingImageView.snp.bottom).offset(40)
            make.right.equalToSuperview()
            make.height.equalTo(44)
            make.bottom.equalTo(scrollView)
        }
    }
}

// MARK: - UITableViewDelegate/UITableViewDataSource
extension ReviewWeViewController: UITableViewDelegate, UITableViewDataSource {
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return titleArray.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        var cell = tableView.dequeueReusableCell(withIdentifier: "reviewresuseridentifier")
        if cell == nil {
            cell = UITableViewCell(style: .value1, reuseIdentifier: "reviewresuseridentifier")
        }
        cell?.textLabel?.font = UIFont.systemFont(ofSize: 12)
        cell?.textLabel?.textColor = UIColor ( red: 0.5296, green: 0.5296, blue: 0.5296, alpha: 1.0 )
        cell?.textLabel?.text = titleArray[indexPath.row] as? String
        
        cell?.detailTextLabel?.font = UIFont.systemFont(ofSize: 12)
        cell?.detailTextLabel?.textColor = UIColor ( red: 0.3258, green: 0.3258, blue: 0.3258, alpha: 1.0 )
        cell?.detailTextLabel?.numberOfLines = 0
        cell?.detailTextLabel?.text = realArray[indexPath.row] as? String
        
        return cell!
    }
    
    func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
        return 44
    }
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
    }
    
}
